<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>弓友之家</title>
    <link rel="stylesheet" href="css/mui.css" />
    <link rel="stylesheet" href="fonts/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" /> 
    <style>
    	.mui-scroll-wrapper{padding-top: 42px !important;}
    	.experience-title{top: 0;}
    </style>
</head>
<body>

	<div class="mui-content">
		<div class="experience-title mui-clearfix">
			<a data-key="0" class="on">全部帖子</a>
			<a data-key="1">资讯</a>
			<a data-key="2">专栏</a>
		</div>
		<div class="mui-scroll-wrapper" id="experience_content">
		    <div class="mui-scroll">
		        <div class="experience-content">
		        	
		        </div>
		    </div>
		</div>
	</div>
	
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" charset="utf-8">
      	mui.init();
      	var key=0;
      	$(".experience-title").on("tap","a",function(){
      		key=$(this).attr("data-key");
      		$(this).addClass("on").siblings().removeClass("on");
      		getList()
      	})
      	
      	var page=1;
      	mui.init({ 
		    pullRefresh : {
		        container:"#experience_content",
		        down : {
		            height:50,
		            auto: true,
		            contentdown : "下拉可以刷新",
		            contentover : "释放立即刷新",
		            contentrefresh : "正在刷新...",
		            callback : getList 
		        },
		        up : { 
		            height:50,
		            auto:false,
		            contentrefresh : "正在加载...",
		            contentnomore:'没有更多数据了',
		            callback : getListByPage 
		        }
		    },
		}); 
		
		function getList(){
			mui.ajax(H_SRC+'/amier/index/experience',{
				data:{
					token:token,
					page:1,
					key:key
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；            
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						var html="";
						for(var i=0;i<dataurl.length;i++){
							html+='<dl class="mui-clearfix"><a data-id="'+dataurl[i].id+'">';
		        			html+='<dt><img src="'+H_SRC+''+dataurl[i].thumb+'"/></dt>';
		        			html+='<dd><h4 class="mui-ellipsis-2"><span>帖子</span>'+dataurl[i].title+'</h4>';
		        			html+='<p>'+dataurl[i].c_time+'</p></dd></a></dl>';
						} 
						$('.experience-content').html(html);
						mui('#experience_content').pullRefresh().endPulldownToRefresh();
			            //重置上拉
			            mui('#experience_content').pullRefresh().refresh(true);
			            page = 2;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
		function getListByPage(){
		    var _this = this;
		    mui.ajax(H_SRC+'/amier/index/experience',{
				data:{
					page:page,
					token:token,
					key:key
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				headers:{'Authorization':token},              
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						if(dataurl.length == 0){
			                _this.endPullupToRefresh(true);
			                return false;
			            }
						
						for(var i=0;i<dataurl.length;i++){ 
							var html="";
							html+='<dl class="mui-clearfix"><a data-id="'+dataurl[i].id+'">';
		        			html+='<dt><img src="'+H_SRC+''+dataurl[i].thumb+'"/></dt>';
		        			html+='<dd><h4 class="mui-ellipsis-2"><span>帖子</span>'+dataurl[i].title+'</h4>';
		        			html+='<p>'+dataurl[i].c_time+'</p></dd></a></dl>';
							$('.experience-content').append(html);
						}
						_this.endPullupToRefresh(false);
		            	page++;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
		
		$(".experience-content").on("tap","a",function(){
			var nid=$(this).attr("data-id");
			mui.openWindow({
				url:'experience-page.html',
				id:'experience-page.html',
				createNew:true,
				extras:{
					nid:nid
				},
				show: {
					autoShow: true,
					aniShow: 'slide-in-right',
					duration: 200
				}
			});
		})
    </script>
</body>
</html>